using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace ImFeelingLucky
{
    public partial class frmFeelingLucky : Form
    {
        string text = "";

        public frmFeelingLucky(string text)
        {
            InitializeComponent();
            chbxUseLink.Checked = true;
            txbxLink.Text = text;
            textChange(this, null);

            if (chbxUseLink.Checked == true)
            {
                txbxSearch.Enabled = false;
            }
        }

        private void checkChange(object sender, EventArgs e)
        {
            if (chbxUseLink.Checked == false)
            {
                txbxSearch.Enabled = true;
            }
            if (chbxUseLink.Checked == true)
            {
                txbxSearch.Enabled = false;
            }            
        }

        private void textChange(object sender, EventArgs e)
        {
            if (chbxUseLink.Checked == true)
            {
                txbxSearch.Text = txbxLink.Text;
            }
        }

        public string getText
        {
            get { return text; }
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            string link = "";
            
            if (chbxLink.Checked == true)
            {
                link = " target=\"_blank\"";
            }
          
            if (txbxSearch.Text == "" || txbxLink.Text == "")
            {
                MessageBox.Show("Sorry, not all fields have been entered correctly", "Big Fat Hairy Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                text = string.Format("<a href=\"http://www.google.com/search?btnI=I'm Feeling Lucky&q={0}\"{1}>{2}</a>", txbxSearch.Text, link, txbxLink.Text);
                this.DialogResult = DialogResult.OK;
                this.Close();
            }
        }
    }
}